package org.larkdoc.controller;

import org.larkdoc.constant.ViewConts;
import org.larkdoc.model.vo.DocVO;
import org.larkdoc.model.vo.PageVO;
import org.larkdoc.model.vo.RespBaseVO;
import org.larkdoc.service.DocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * 默认首页控制器
 * 
 * @author  zhangpeijun
 * @version  [v1.0.1, 2017年3月15日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Controller
@RequestMapping("/")
public class HomeController {
    
    @Autowired
    DocService docService;
    
    public String index() {
        return "index.html";
    }

    @RequestMapping(value = "/unauthorized")
    @ResponseBody
    public RespBaseVO logout() {
        RespBaseVO respVo = new RespBaseVO();
        respVo.setRetCode(ViewConts.Code.NO_PSERMISSION);
        respVo.setRetMsg(ViewConts.Msg.NO_PSERMISSION);
        return respVo;
    }
    
    @RequestMapping(value = "/home/list")
    @ResponseBody
    public RespBaseVO list() {
        RespBaseVO respVo = new RespBaseVO();
        PageVO<DocVO> page = new PageVO<DocVO>(); 
        DocVO doc = new DocVO();
        doc.setVisibleRange(3);
        page.setSearch(doc);
        respVo.setRetVal(docService.page(page));
        return respVo;
    }
    
    @RequestMapping(value = "/home/search")
    @ResponseBody
    public RespBaseVO search(DocVO doc) {
        RespBaseVO respVo = new RespBaseVO();
        PageVO<DocVO> page = new PageVO<DocVO>();
        doc = null == doc ? new DocVO() : doc;
        doc.setVisibleRange(3);
        page.setSearch(doc);
        respVo.setRetVal(docService.page(page));
        return respVo;
    }
    
}
